import { http } from "@/utils/http";
import { baseUrlApi, filerEmptyVal } from "../utils";

/** 商品列表查询 */
export const getGoodsList = (params?: object) => {
  return http.request<any>("get", baseUrlApi("/goods/page"), {
    params: filerEmptyVal(params)
  });
};

/** 商品日志列表查询 */
export const getGoodsOptList = (params?: object) => {
  return http.request<any>("get", baseUrlApi("/goods/opt/log/page"), {
    params: filerEmptyVal(params)
  });
};

/** 新增商品 */
export const addGoods = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/goods/add"), {
    data: filerEmptyVal(data)
  });
};

/** 商品详情 */
export const getGoodsDetail = id => {
  return http.request<any>("get", baseUrlApi("/goods/detail?id=" + id));
};

/** 修改商品 */
export const upGoods = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/goods/update"), { data });
};

/** 批量停用或批量启用 */
export const batchUpGoodsStatus = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/goods/changeGoodsStatus"), {
    data
  });
};

/** 批量推荐 */
export const batchRecommendGoods = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/goods/recommend"), {
    data
  });
};

/** 导入价格模版 */
export const importGoodsPriceTemp = () => {
  return http.request<any>(
    "get",
    baseUrlApi("/goods/template/import/specBrandRel")
  );
};

/** 导入价格 */
export const importGoodsPrice = (data?: object) => {
  return http.request<any>(
    "post",
    baseUrlApi("/goods/import/specBrandRel"),
    {
      data,
      params: {
        isShowErrTips: false
      }
    },
    {
      headers: {
        "Content-Type": "multipart/form-data"
      }
    }
  );
};

/** 导入商品 */
export const importGoodsList = (data?: object) => {
  return http.request<any>(
    "post",
    baseUrlApi("/goods/import/goods"),
    {
      data,
      params: {
        isShowErrTips: false
      }
    },
    {
      headers: {
        "Content-Type": "multipart/form-data"
      }
    }
  );
};

/** 规格关联品牌 */
export const setGoodsSpen = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/goods/specBrandRel"), { data });
};

/** 删除规格 */
export const delGoodsSpec = (id?: number) => {
  return http.request<any>("post", baseUrlApi("/goods/delete/spec?id=" + id));
};

/** 删除商品 */
export const delGoods = (id?: number) => {
  return http.request<any>("post", baseUrlApi("/goods/delete?id=" + id));
};

//  其他 ================================

/** 记录单位列表查询 */
export const getUnitItemList = (params?: object) => {
  return http.request<any>("get", baseUrlApi("/unit/item/page"), { params });
};

/** 兑换规则列表查询 */
export const getRuleList = (params?: object) => {
  return http.request<any>("get", baseUrlApi("/rule/page"), { params });
};
